﻿using AnesSystem.Models;
using AnesSystem.Services;
using Common;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace AnesSystem.ViewModels
{
    public class ApplyOperationCtrlViewModel : BaseViewModel<ApplyOperationCtrlViewModel>
    {

        private string _age;
        private PatientLinkModel _disPatientLink;
        private ConfigDepartmentsModel _configDepartmentsModel ;
        private List<ConfigDepartmentsModel> _configDepartmentsModelList ;
        private string _xb;
        private string _xx;
        private string _selectedAgeUnit = "岁";
        #region Variables
        private List<string> _ageList = new List<string>();
        private List<string> _xbList = new List<string>();
        private List<string> _xxList = new List<string>();

        #endregion


        #region Constructor
        public ApplyOperationCtrlViewModel()
        {
            ConfigDepartmentsModelList = DataManager.Instance.ConfigDepartmentsModelList.ToList();
            _ageList.Add("岁");
            _ageList.Add("月");
            _ageList.Add("天");

            _xxList.Add("");
            _xxList.Add("O Rh+");
            _xxList.Add("O Rh-");
            _xxList.Add("A Rh+");
            _xxList.Add("A Rh-");
            _xxList.Add("B Rh+");
            _xxList.Add("B Rh-");
            _xxList.Add("AB Rh+");
            _xxList.Add("AB Rh-");
            _xxList.Add("缺");

            _xbList.Add("");
            _xbList.Add("男");
            _xbList.Add("女");
        }


        #endregion


        #region Properties
        public PatientLinkModel DisPatientLink
        {
            get
            {
                return _disPatientLink;
            }

            set
            {
                _disPatientLink = value;
                RaisePropertyChanged("DisPatientLink");
            }
        }

        public string Age
        {
            get
            {
                return _age;
            }

            set
            {
                _age = value;
                RaisePropertyChanged("Age");
            }
        }

        public List<string> AgeList
        {
            get
            {
                return _ageList;
            }

            set
            {
                _ageList = value;
                RaisePropertyChanged("AgeList");
            }
        }

        public ConfigDepartmentsModel ConfigDepartmentsModel
        {
            get
            {
                return _configDepartmentsModel;
            }

            set
            {
                _configDepartmentsModel = value;
                RaisePropertyChanged("ConfigDepartmentsModel");
            }
        }

        public string Xb
        {
            get
            {
                return _xb;
            }

            set
            {
                _xb = value;
                RaisePropertyChanged("Xb");
            }
        }

        public string Xx
        {
            get
            {
                return _xx;
            }

            set
            {
                _xx = value;
                RaisePropertyChanged("Xx");
            }
        }

        public string SelectedAgeUnit
        {
            get
            {
                return _selectedAgeUnit;
            }

            set
            {
                _selectedAgeUnit = value;
                RaisePropertyChanged("SelectedAgeUnit");
            }
        }

        public List<string> XbList
        {
            get
            {
                return _xbList;
            }

            set
            {
                _xbList = value;
            }
        }

        public List<string> XxList
        {
            get
            {
                return _xxList;
            }

            set
            {
                _xxList = value;
            }
        }

        public List<ConfigDepartmentsModel> ConfigDepartmentsModelList
        {
            get
            {
                return _configDepartmentsModelList;
            }

            set
            {
                _configDepartmentsModelList = value;
            }
        }

        #endregion


        #region 依赖属性


        #endregion


        #region Event


        #endregion


        #region PrivateMethods


        public void init()
        {
            ConfigDepartmentsModel = new ConfigDepartmentsModel();
            DisPatientLink = new PatientLinkModel();
            SelectedAgeUnit = "岁";
            Xx = "";
            Xb = "";
            Age = "";
        }

        #endregion


        #region Public/ProtectedMethods
        public void InsertPatient()
        {
            if (CheckNewOper())
            {
                DisPatientLink.CreateDate = DateTime.Now;
                DisPatientLink.Patient.Ksmc = _configDepartmentsModel.Name;
                DisPatientLink.Patient.Xx = Xx;
                DisPatientLink.Patient.Xb = Xb;
                DisPatientLink.Patient.Nl = Age + SelectedAgeUnit;
                if ("岁".Equals(SelectedAgeUnit))
                {
                    DisPatientLink.Patient.NumAge = (int)Age.ToDouble();
                }
                else
                {
                    DisPatientLink.Patient.NumAge = 0;
                }
                DisPatientLink.Patient.Status = Constants.FLAG_VALID;
                DisPatientLink.Application.Detailstatus = Constants.OR_STATUS_FLAG_APPLIED;
                DisPatientLink.Application.Status = Constants.AP_STATUS_MAZUIQIAN;
                PatientLinkService.Instance.AddUpdate(DisPatientLink);
                init();
            }
        }

        public bool CheckNewOper()
        {
            bool flag = true;
            if (DisPatientLink.Application.Yysssj == new DateTime())
            {
                MessageBoxCommon.ShowDialog("计划时间未填写", MessageBoxCommon.OK);
                return false;
            }
            if (string.IsNullOrEmpty(DisPatientLink.Application.Sqzd1))
            {
                MessageBoxCommon.ShowDialog("术前诊断未填写", MessageBoxCommon.OK);
                return false;
            }
            if (string.IsNullOrEmpty(DisPatientLink.Application.Nsssmc))
            {
                MessageBoxCommon.ShowDialog("拟施手术未填写", MessageBoxCommon.OK);
                return false;
            }
            return flag;
        }

        #endregion


        #region EventHandlers


        #endregion
    }
}
